{extend name="admin/base" /}
{block name="resources"/}
<style>
select{
	width:134px;
}
</style>


{/block}
{block name="main"}
<div class="set-style">
	<dl>
		<dt><span style="color:red;">*</span>&nbsp;&nbsp;自提点名称:</dt>
		<dd>
			<p><input id="name" type="text" value="{$pickupPoint_detail['name']}"></p>
			<p class="error">自提点名称不能为空</p>
		</dd>
	</dl>
	<dl>
		<dt><span style="color:red;">*</span>&nbsp;&nbsp;自提点地址:</dt>
		<dd>
			<p>
				<select name="province" id="seleAreaNext" onchange="GetProvince();" value="{$pickupPoint_detail['province_id']}">
					<option value="">请选择省</option>
				</select>
				<select name="city" id="seleAreaThird" onchange="getSelCity();" value="{$pickupPoint_detail['city_id']}">
					<option value="">请选择市</option>
				</select>
				<select name="district" id="seleAreaFouth" value="{$pickupPoint_detail['district_id']}">
					<option value="-1">请选择区/县</option>
				</select>
			
			</p>
			<p class="error">请选择自提点完整地址</p>
		</dd>
	</dl>
	<dl>
		<dt><span style="color:red;">*</span>&nbsp;&nbsp;详细地址:</dt>
		<dd>
			<p><input id="address" type="text" value="{$pickupPoint_detail['address']}"></p>
			<p class="error">详细地址不能为空</p>
		</dd>
	</dl>
	<dl>
		<dt>自提点联系人:</dt>
		<dd>
			<p><input id="contact" type="text" value="{$pickupPoint_detail['contact']}"></p>
		</dd>
	</dl>
	<dl>
		<dt><span style="color:red;">*</span>&nbsp;&nbsp;自提点电话:</dt>
		<dd>
			<p><input id="phone" type="text" value="{$pickupPoint_detail['phone']}"></p>
			<p class="error">自提点电话不能为空</p>
		</dd>
	</dl>
	<input type="hidden" id="provinceid" value="{$pickupPoint_detail['province_id']}">
	<input type="hidden" id="cityid" value="{$pickupPoint_detail['city_id']}">
	<input type="hidden" id="districtid" value="{$pickupPoint_detail['district_id']}">
	<input type="hidden" id="pickip_id" value="{$pickip_id}"/>
	<button class="edit_button" onclick="updateReturnAjax();">提交</button>
</div>
 <script>

//选择省份弹出市区
 function GetProvince() {
	
 	var id = $("#seleAreaNext").find("option:selected").val();
 	var selCity = $("#seleAreaThird")[0];
 	for (var i = selCity.length - 1; i >= 0; i--) {
 		selCity.options[i] = null;
 	}
 	
 	var opt = new Option("请选择市", "-1");
 	selCity.options.add(opt);
 	$.ajax({
 		type : "post",
 		url : "{:__URL('ADMIN_MAIN/shop/getcity')}",
 		dataType : "json",
 		data : {
 			"province_id" : id
 		},
 		success : function(data) {
 			if (data != null && data.length > 0) {
 				for (var i = 0; i < data.length; i++) {
 					var opt = new Option(data[i].city_name,data[i].city_id);
 					selCity.options.add(opt);
 				}
 				if(typeof($("#cityid").val())!='undefined'){
 					$("#seleAreaThird").val($("#cityid").val());
 					getSelCity();
 					$("#cityid").val('-1');
 				}
 			}
 		}
 	});
 };
 // 选择市区弹出区域
 function getSelCity() {
 	var id = $("#seleAreaThird").find("option:selected").val();
 	var selArea = $("#seleAreaFouth")[0];
 	for (var i = selArea.length - 1; i >= 0; i--) {
 		selArea.options[i] = null;
 	}
 	var opt = new Option("请选择区/县", "-1");
 	selArea.options.add(opt);
 	$.ajax({
 		type : "post",
 		url : "{:__URL('ADMIN_MAIN/shop/getdistrict')}",
 		dataType : "json",
 		data : {
 			"city_id" : id
 		},
 		success : function(data) {
 			if (data != null && data.length > 0) {
 				for (var i = 0; i < data.length; i++) {
 					var opt = new Option(data[i].district_name,data[i].district_id);
 					selArea.options.add(opt);
 				}
 				if(typeof($("#districtid").val())!='undefined'){
 					$("#seleAreaFouth").val($("#districtid").val());
 					$("#districtid").val('-1');
 				}
 				
 			}
 		}
 	});
 }

 $(function() {
	
 	var selCity = $("#seleAreaNext")[0];
 	for (var i = selCity.length - 1; i >= 0; i--) {
 		selCity.options[i] = null;
 	}
 	var opt = new Option("请选择省", "-1");
 	selCity.options.add(opt);
 	//alert(selCity);
 	// 添加省
 	$.ajax({
 		type : "post",
 		url : "{:__URL('ADMIN_MAIN/shop/getprovince')}",
 		dataType : "json",
 		success : function(data) {
//  			alert(JSON.stringify(data));
 			if (data != null && data.length > 0) {
 				for (var i = 0; i < data.length; i++) {
 					var opt = new Option(data[i].province_name,
 							data[i].province_id);
 					selCity.options.add(opt);
 				}
 				if(typeof($("#provinceid").val())!='undefined'){
 					$("#seleAreaNext").val($("#provinceid").val());
 					GetProvince();
 					$("#provinceid").val('-1');
 				}
 			}
 		}
 	});
 });
 
 
 
	/**
	 *添加自提点
	 **/
	function updateReturnAjax() {
		var id = $("#pickip_id").val();
		var name = $("#name").val();
		var address = $("#address").val();
		var province = $("#seleAreaNext").val();
		var city = $("#seleAreaThird").val();
		var district = $("#seleAreaFouth").val();
		var contact = $("#contact").val();
		var phone = $("#phone").val();
		if (name == '') {
			$("#name").parent().next().show();
			return false;
		}else{
			$(".error").hide();
		}
		if(address == ''){
			$("#address").parent().next().show();
			return false;
		}else{
			$(".error").hide();
		}
		if ($("#seleAreaFouth").val() < 0 || $("#seleAreaFouth").val() == "") {
// 			if ($("#seleAreaNext").val() == "" || $("#seleAreaNext").val() < 0) {
// 				showBox("请选择省份");
// 				$("#seleAreaNext").focus();
// 				return false;
// 			}
// 			if ($("#seleAreaThird").val() == "" || $("#seleAreaThird").val() < 0) {
// 				showBox("请选择市");
// 				$("#seleAreaThird").focus();
// 				return false;
// 			}
// 			if ($("#seleAreaFouth").val() == "" || $("#seleAreaFouth").val() < 0) {
// 				showBox("请选择区/县");
// 				$("#seleAreaFouth").focus();
// 				return false;
// 			}
			$("#seleAreaFouth").parent().next().show();
			return false;
		}else{
			$(".error").hide();
		}
		
		if(phone.length == 0){
			$("#phone").parent().next().show();
			return false;
		} else {
			$(".error").hide();
		}
		
		
		$.ajax({
			type : "post",
			url : "{:__URL('ADMIN_MAIN/shop/updatepickuppoint')}",
			data : {
				'id' :id,
				'name' : name,
				'address' : address,
				'contact' : contact,
				'phone' : phone,
				'province_id' : province,
				'city_id' : city,
				'district_id' : district
			},
			async : true,
			success : function(data) {
				if (data['code'] > 0) {
					    showMessage('success', data["message"],window.location.href=__URL("ADMIN_MAIN/shop/pickuppointlist"));

				} else {
						showMessage('error', data["message"]);
					
				}
			}
		});
	}
</script>
{/block}